﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Basic global alias for the main class containing constants
using r = Rougeliek.Rougeliek;

namespace Rougeliek
{
    class Mob
    {
        // Basic mob statistics an ting
        public int x, y;
        public char sprite = 'M';

        public void spawnMob()
        {
            // When spawning, set some random position
            Random rdmx = new Random((int)DateTime.Now.Ticks);
            Random rdmy = new Random((int)DateTime.Now.Ticks);
            x = rdmx.Next(r.SCREENMIN, r.SCREENX);
            y = rdmy.Next(r.SCREENMIN, r.SCREENY);

            // Check if the spawn position is where the player is, if so, respawn
            while (x == r.pc.x && y == r.pc.y)
            {
                x = rdmx.Next(r.SCREENMIN, r.SCREENX);
                y = rdmy.Next(r.SCREENMIN, r.SCREENY);
            }
            
        }

        // Basic movement for a mob, tries to close the distance on the player, first on the x axis
        // then on the y axis while also checking for collisions. Yes it's dumb as a post, but hey,
        // i'm not an ai programmer (or a programmer at all!)
        public void moveMob()
        {
            // Temporary coordinates containing the mob's current position,
            // used to send to drawBufferTile() to render the mob's updated
            // position and clear the previous position's tile
            int tempX = x;
            int tempY = y;

            // Slowly move towards the player and check if the desired tile
            // is obstructed or not. If it's not obstructed, creep towards the
            // player in a semi retarded fashion
            if (x < r.pc.x && Map.checkCollision(x + 1, y) == false)
            {
                x++;
                ScreenBuffer.drawBufferTile(tempX, tempY);
            }
            else if (x > r.pc.x && Map.checkCollision(x - 1, y) == false)
            {
                x--;
                ScreenBuffer.drawBufferTile(tempX, tempY);
            }
            else if (y < r.pc.y && Map.checkCollision(x, y + 1) == false)
            {
                y++;
                ScreenBuffer.drawBufferTile(tempX, tempY);
            }
            else if (y > r.pc.y && Map.checkCollision(x, y - 1) == false)
            {
                y--;
                ScreenBuffer.drawBufferTile(tempX, tempY);
            }
        }
    }
}
